<template>
	<view style="padding: 30rpx;">
		<u-form ref="form" :model="formData" :rules="rules">
			<u-form-item prop="name" label="" label-width="0" v-if="cType==2">
				<view style="background: #f1f1f1;flex: 1;border-radius: 4px;padding: 6rpx 0;">
					<u-input v-model="formData.name" placeholder="请输入昵称" clearable border="false" maxlength="20"></u-input>
				</view>
			</u-form-item>
			<u-form-item prop="workCorp" label="" label-width="0" v-if="cType==6">
				<view style="background: #f1f1f1;flex: 1;border-radius: 4px;padding: 6rpx 0;">
					<u-input v-model="formData.workCorp" placeholder="请输入工作单位" clearable border="false" maxlength="50"></u-input>
				</view>
			</u-form-item>
			<u-form-item prop="dept" label="" label-width="0" v-if="cType==7">
				<view style="background: #f1f1f1;flex: 1;border-radius: 4px;padding: 6rpx 0;">
					<u-input v-model="formData.dept" placeholder="请输入所在班组" clearable border="false" maxlength="20"></u-input>
				</view>
			</u-form-item>
			<u-form-item prop="city" label="所在地区" label-width="70" borderBottom="true" v-if="cType==8">
				<view style="flex: 1;padding: 6rpx 0;display: flex;align-items: center;justify-content: space-between;font-size: 28rpx;" @click="itemClick()">
					<view style="padding: 6px 9px;">
						<text v-if="formData.city">{{formData.city}}</text>
						<text v-else style="color: #aaa;">请选择</text>
					</view>
					<u-icon name="arrow-right" color="#888"></u-icon>
				</view>
			</u-form-item>
			<u-form-item prop="address" label="详细地址" label-width="70" borderBottom="true" v-if="cType==8">
				<view style="flex: 1;padding: 6rpx 0;">
					<u-input v-model="formData.address" placeholder="请输入" clearable border="false" maxlength="50"></u-input>
				</view>
			</u-form-item>
		</u-form>
		
		<view style="margin-top: 30rpx;">
			<u-button type="primary" @click="onsubmit()">确定</u-button>
		</view>
		
		<!-- <address-picker
			:show="isShow"
			closeOnClickOverlay
			@confirm="confirmAddress"
			@cancel="isShow = false"
			@close="isShow = false"
			:address-data="addressData"
			:indexs="indexs"
			:areaId="areaId"
			:type="3"
		></address-picker> -->
	</view>
</template>

<script setup>
import { ref } from 'vue';
import { onLoad } from "@dcloudio/uni-app";
import { personInfoEdit } from '@/api/qss/zxhapi.js'
const cType = ref(0)
const isShow = ref(false)
const indexs = ref([])
const areaId = ref([])
const addressData = ref(['北京市', '北京市', '东城区'])
const form = ref('')
const formData = ref({
	name:'',
	workCorp:'',
	dept:'',
	city: '',
	address:'',
})
const rules = ref({
    name:[{ required: true, message: '请输入昵称' }],
    workCorp:[{ required: true, message: '请输入工作单位' }],
    dept:[{ required: true, message: '请输入所在班组' }],
    city:[{ required: true, message: '请选择地区' }],
    address:[{ required: true, message: '请输入详细地址' }],
})

function onsubmit(){
	form.value.validate().then(() => {
		if (RegExp('platform=corp').test(formData.value.avatar)) {
			formData.value.avatar = formData.value.avatar.split('?platform=corp')[0]
		}
		personInfoEdit(formData.value).then(res=>{
			if(res.code == 200){
				uni.showToast({ title: "提交成功", duration: 1000 })
				setTimeout(()=>{
					uni.navigateBack()
				}, 1000)
			}
		}).finally(()=>{
			uni.hideLoading()
		})
	}).catch(err => {
		//验证未通过
	})
}

function itemClick(){
	isShow.value = true
}

function confirmAddress(val) {
	formData.value.city = val.value.join('')
	isShow.value = false
}

onLoad((option)=>{
	cType.value = option.type || 0
	uni.setNavigationBarTitle({
		title: cType.value==2?'昵称修改':cType.value==6?'工作单位修改':cType.value==7?'所在班组修改':cType.value==8?'常住地址修改':'编辑资料'
	})
	// if(option.name&&option.val){
	// 	formData.value[option.name] = option.val
	// }
	formData.value = uni.getStorageSync('qssuseredit')
})

</script>

<style lang="less">

</style>